package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class FindOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("查找图书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要查找的图书名称：");
        String name = scanner.next();
        // 获取当前图书数量
        int currentSize = bookList.getUsedSize();
        // 遍历图书数组
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)) {
                System.out.println("成功查到该书，信息如下：");
                System.out.println(book);
                return;
            }
        }
        System.out.println("未找到该书，书名或该书不存在");
    }
}
